<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请人">
              <select-user-by-dep :multi="false" v-model="queryParam.handlerId" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="调入团队">
              <select-team-input placeholder="请选择调入团队" v-model="queryParam.foldTeamId" :teamType="0" :tdlx="3" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="调出团队">
              <select-team-input placeholder="请选择调出团队" v-model="queryParam.exportTeamId" :teamType="0" :tdlx="3" />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">

          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('物资调拨申请清单')"
        :disabled="isDisabledAuth('erpPurchaseCannibalize:export')">导出</a-button>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item, index) in defColumns">
                <template v-if="item.key != 'rowIndex' && item.dataIndex != 'action'">
                  <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style="iconStyle" /></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
          selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table ref="table" size="middle" :scroll="{ x: '110%' }"
        :components="draggableComponent" bordered rowKey="id" :columns="columns"
        :dataSource="dataSource" :pagination="ipagination" :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" class="j-table-force-nowrap"
        @change="handleTableChange">
        <a slot="purchaseBill" slot-scope="text, record" @click="getDetail(record.id)">{{ text }}</a>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter" />
        </template>
        <template slot="action" slot-scope="text, record">
          <a-button type="primary" size="small" v-show="record.operationType === '1'" @click="outStore(record, 'out')"
            v-has="'ErpPurchaseCannibalizeFinalList:outbound'">出库</a-button>
          <a-button type="primary" size="small" v-show="record.operationType === '2'" @click="outStore(record, 'inbound')"
            v-has="'ErpPurchaseCannibalizeFinalList:inbound'">入库</a-button>
          <a-button type="primary" size="small" v-show="record.operationType === '3'" @click="outStore(record, 'detail')"
            v-has="'ErpPurchaseCannibalizeFinalList:boundRecord'">出库记录</a-button>
        </template>

      </a-table>
    </div>

    <erp-purchase-cannibalize-modal ref="modalForm" @ok="modalFormOk"></erp-purchase-cannibalize-modal>
    <bpm-biz-task-deal-modal ref="taskDealModal" :path="path" :formData="formData"
      @ok="handleOk"></bpm-biz-task-deal-modal>
    <bpm-process-track-modal ref="bpmProcessTrackModal"></bpm-process-track-modal>
    <biz-task-notify-modal ref="taskNotifyModal"></biz-task-notify-modal>
    <biz-task-notify-me-modal ref="taskNotifyMeModal"></biz-task-notify-me-modal>
    <process-config-modal ref="processConfig" @ok="handleSuccess"></process-config-modal>
    <!-- 物资领用明细 -->
    <ErpPurchaseOutStoreDetail ref="outStoreDetail" @refresh="searchQuery" page="cannibalize"></ErpPurchaseOutStoreDetail>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
import BpmBizTaskDealModal from '@/views/modules/bpmbiz/common/BpmBizTaskDealModal.vue';
import BpmProcessTrackModal from '@/views/modules/bpmbiz/common/BpmProcessTrackModal.vue';
import BizTaskNotifyModal from '@/views/modules/bpmbiz/common/BizTaskNotifyModal.vue';
import BizTaskNotifyMeModal from '@/views/modules/bpmbiz/common/BizTaskNotifyMeModal.vue';
import ErpPurchaseCannibalizeModal from './modules/ErpPurchaseCannibalizeModal'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
import ProcessConfigModal from '@/views/scy/components/ProcessConfigModal'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import ErpPurchaseOutStoreDetail from './modules/ErpPurchaseOutStoreDetail'

export default {
  name: 'ErpPurchaseCannibalizeList',
  mixins: [JeecgBpmListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpPurchaseCannibalizeModal,
    BpmBizTaskDealModal,
    BpmProcessTrackModal,
    BizTaskNotifyModal,
    BizTaskNotifyMeModal,
    SelectTeamInput,
    ProcessConfigModal,
    SelectUserByDep,
    ErpPurchaseOutStoreDetail
  },
  data() {
    return {
      description: '物资调拨申请单管理页面',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '单据编号',
          align: 'center',
          width: 200,
          dataIndex: 'purchaseBill',
          scopedSlots: { customRender: 'purchaseBill' },
          ellipsis: true
        },
        {
          title: '申请人',
          align: 'center',
          width: 200,
          dataIndex: 'proposer_dictText',
          ellipsis: true,
        },
        {
          title: '申请时间',
          align: 'center',
          width: 200,
          dataIndex: 'createTime',
          customRender: function (text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          },
          ellipsis: true,
        },
        {
          title: '调入团队',
          align: 'center',
          width: 300,
          dataIndex: 'foldTeamId_dictText',
          ellipsis: true,
        },
        {
          title: '调出团队',
          align: 'center',
          width: 300,
          dataIndex: 'exportTeamId_dictText',
          ellipsis: true,
        },
        {
          title: '物品用途',
          align: 'center',
          width: 300,
          dataIndex: 'purchaseUse',
          ellipsis: true
        },
        {
          title: '操作',
          align: 'center',
          dataIndex:"action",
          scopedSlots: { customRender: 'action' },
          width: 180,
          fixed: 'right'
        },
      ],
      url: {
        list: '/api/erp/purchase/recipients/erpPurchaseCannibalize/finalList',
        delete: '/api/erp/purchase/recipients/erpPurchaseCannibalize/delete',
        deleteBatch: '/api/erp/purchase/recipients/erpPurchaseCannibalize/deleteBatch',
        exportXlsUrl: '/api/erp/purchase/recipients/erpPurchaseCannibalize/exportFinalXls',
        importExcelUrl: 'api/erp/purchase/recipients/erpPurchaseCannibalize/importExcel',
        bizCount: '/api/erp/purchase/recipients/erpPurchaseCannibalize/bizCount'
      },
      // 代码生成后需手动设置流程编码
      flowCode: 'onl_erp_purchase_cannibalize',
      formUrl: '/erp/purchase/recipients/modules/ErpPurchaseCannibalizeForm',
      formUrlMobile: '/pages/synergy/erpPurchaseCannibalizeList',
      dictOptions: {},
      superFieldList: [],
      processId: '1540224492159131650',
      beanName: 'erpPurchaseCannibalizeServiceImpl',
      queryParam: {
        bpmStatus: '3'
      }
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    //查看详情
    getDetail(id) {
      this.$router.push({
        path: `/erp/purchase/recipients/ErpPurchaseCannibalizeListDetail/${id}`,
      })
    },
    initDictConfig() {
    },
    beginProcess(record) {
      this.$refs.processConfig.visible = true
      this.$refs.processConfig.formUrl = this.formUrl
      this.$refs.processConfig.formUrlMobile = this.formUrlMobile
      this.$refs.processConfig.flowCode = this.flowCode
      this.$refs.processConfig.edit(record, this.processId, this.beanName)
    },
    handleSuccess() {
      this.loadData();
      this.$refs.modalForm.handleCancel()
      this.onClearSelected();
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'datetime', value: 'createTime', text: '创建日期' })
      fieldList.push({ type: 'string', value: 'purchaseBill', text: '单据编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'employeeId', text: '申请人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'applicant', text: '申请单位', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'purchaseUse', text: '物品用途', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'remark', text: '备注', dictCode: '' })
      fieldList.push({ type: 'string', value: 'foldApplicant', text: '调入单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'foldTeamId', text: '调入团队', dictCode: '' })
      fieldList.push({ type: 'date', value: 'foldTime', text: '调入日期' })
      fieldList.push({ type: 'string', value: 'foldWarehouse', text: '调入仓库', dictCode: '' })
      fieldList.push({ type: 'string', value: 'exportApplicant', text: '调出单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'exportTeamId', text: '调出团队', dictCode: '' })
      fieldList.push({ type: 'date', value: 'exportTime', text: '调出日期' })
      fieldList.push({ type: 'string', value: 'exportWarehouse', text: '调出仓库', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'purchaseFile', text: '附件信息', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bpmStatus', text: '流程状态', dictCode: '' })
      this.superFieldList = fieldList
    },
    searchQuery() {
      this.onClearSelected();
      this.queryParam.bpmStatus = '3'
      this.loadData(1);
    },
    searchReset() {
      this.onClearSelected();
      if (this.bizTaskType) {
        this.queryParam = { bizTaskType: this.bizTaskType };
      }
      this.queryParam.bpmStatus = '3'
      this.loadData(1);
    },

    //出库
    outStore(record, type) {
      this.$refs.outStoreDetail.showModal(record, type)
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
